<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>编辑用户</title>
    <link rel="stylesheet" th:href="@{/layuimini/lib/layui-v2.5.5/css/layui.css}"
          href="../../../static/layuimini/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" th:href="@{/layuimini/css/public.css}" href="../../../static/layuimini/css/public.css"
          media="all">
    <style>
        body {
            background-color: #fff;
            padding: 0;
            margin: 0;
        }

        body .layui-layer-btn {
            background-color: #F8F8F8;
            border-top: 1px solid #eee;
            padding-top: 10px;
        }
    </style>
</head>
<body>
<div class="layui-form">
    <form id="userInfoForm">
        <div class="layui-form-item"></div>
        <div class="layui-form-item">
            <label class="layui-form-label">账号：</label>
            <div class="layui-input-inline" style="width: 320px;">
                <input type="text" name="username" th:value="${sysUser!=null?sysUser.username:''}"
                       lay-verify="required" placeholder="请输入账号" autocomplete="off" th:readonly="${sysUser!=null}"
                       class="layui-input">
            </div>
            <div class="layui-form-mid" style="color: red">*</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">姓名：</label>
            <div class="layui-input-inline" style="width: 320px;">
                <input type="text" name="showName" th:value="${sysUser!=null?sysUser.showName:''}"
                       lay-verify="required" placeholder="请输入名称" autocomplete="off"
                       class="layui-input">
            </div>
            <div class="layui-form-mid" style="color: red">*</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码：</label>
            <div class="layui-input-inline" style="width: 320px;">
                <input type="password" name="password"
                       placeholder="请输入密码" autocomplete="off" lay-verify="pass"
                       class="layui-input">
            </div>
            <div class="layui-form-mid" style="color: red" th:text="${sysUser!=null?'':'*'}"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码：</label>
            <div class="layui-input-inline" style="width: 320px;">
                <input type="password" name="password1"
                       placeholder="请再次输入密码" autocomplete="off" lay-verify="pass1"
                       class="layui-input">
            </div>
            <div class="layui-form-mid" style="color: red" th:text="${sysUser!=null?'':'*'}"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机：</label>
            <div class="layui-input-inline" style="width: 320px;">
                <input type="text" name="phone" th:value="${sysUser!=null?sysUser.phone:''}"
                       placeholder="请输入手机号" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱：</label>
            <div class="layui-input-inline" style="width: 320px;">
                <input type="text" name="email" th:value="${sysUser!=null?sysUser.email:''}"
                       placeholder="请输入邮箱" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态：</label>
            <div class="layui-input-inline" style="width: 320px;">

                <input type="checkbox" name="enabled" lay-skin="switch" lay-text="启用|禁用" value="true" th:checked="${sysUser!=null&&sysUser.enabled==true}">

            </div>
        </div>
        <div class="layui-layer-btn layui-layer-btn-">
            <a id="per_save" class="layui-layer-btn0" lay-filter="btn_save" lay-submit>保存</a>
            <a id="edit_cancel" class="layui-layer-btn1">关闭</a>
        </div>
        <!--隐藏域-->
        <input id="userId" type="hidden" name="userId" th:value="${param.userId}">
    </form>
</div>

<script th:src="@{/layuimini/lib/layui-v2.5.5/layui.js}" src="../../../static/layuimini/lib/layui-v2.5.5/layui.js"
        charset="utf-8"></script>
<script th:src="@{/layuimini/js/lay-config.js?v=1.0.4}" src="../../../static/layuimini/js/lay-config.js?v=1.0.4"
        charset="utf-8"></script>
<script th:inline="text">
    layui.use(['form', 'layer'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var layer = layui.layer;


        form.on('submit(btn_save)',function (){
            save();
            return false;
        })
        //保存
        function save() {
            var userInfoFormData = $('#userInfoForm').serialize();
            console.log(userInfoFormData);
            layer.load(2);
            $.ajax({
                type: 'post',
                url: '[[@{/}]]manage/user/userSave',
                data: userInfoFormData,
                dataType: 'json',
                success: function (result) {
                    console.log(result);
                    if (result.success){
                        layer.msg("保存成功");
                        $('#userId').val(result.data.userId);

                    }else{
                        layer.msg(result.msg);
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    layer.msg(textStatus);
                },
                complete: function () {
                    layer.closeAll('loading');
                }
            });
        }

        //取消
        $('#edit_cancel').click(function cancel() {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });

        form.render();
    });
</script>
</body>
</html>